From 851a28404d6ea4ab59fc86a7f757b66b5582d8ec Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 12 May 2017 23:07:42 +0100 Subject: [PATCH] Allow runner params --- src/cargo/ops/cargo_rustc/compilation.rs | 9 +++--- src/cargo/util/config.rs | 35 +++++++++++++++++------- tests/tool-paths.rs | 8 +++--- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index 594f3cb19..be3e16a04 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -54,7 +54,7 @@ pub struct Compilation<'cfg> { config: &'cfg Config, - target_runner: LazyCell>, + target_runner: LazyCell)>>, } impl<'cfg> Compilation<'cfg> { @@ -94,18 +94,19 @@ impl<'cfg> Compilation<'cfg> { self.fill_env(process(cmd), pkg, true) } - fn target_runner(&self) -> CargoResult<&Option> { + fn target_runner(&self) -> CargoResult<&Option<(PathBuf, Vec)>> { self.target_runner.get_or_try_init(|| { let key = format!("target.{}.runner", self.target); - Ok(self.config.get_path(&key)?.map(|v| v.val)) + Ok(self.config.get_path_and_args(&key)?.map(|v| v.val)) }) } /// See `process`. pub fn target_process>(&self, cmd: T, pkg: &Package) -> CargoResult { - let builder = if let &Some(ref runner) = self.target_runner()? { + let builder = if let &Some((ref runner, ref args)) = self.target_runner()? { let mut builder = process(runner); + builder.args(args); builder.arg(cmd); builder } else { diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index aa27fa043..f16110d24 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -215,25 +215,40 @@ impl Config { } } + fn string_to_path(&self, value: String, definition: &Definition) -> PathBuf { + let is_path = value.contains('/') || + (cfg!(windows) && value.contains('\\')); + if is_path { + definition.root(self).join(value) + } else { + // A pathless name + PathBuf::from(value) + } + } + pub fn get_path(&self, key: &str) -> CargoResult>> { if let Some(val) = self.get_string(key)? { - let is_path = val.val.contains('/') || - (cfg!(windows) && val.val.contains('\\')); - let path = if is_path { - val.definition.root(self).join(val.val) - } else { - // A pathless name - PathBuf::from(val.val) - }; Ok(Some(Value { - val: path, - definition: val.definition, + val: self.string_to_path(val.val, &val.definition), + definition: val.definition })) } else { Ok(None) } } + pub fn get_path_and_args(&self, key: &str) -> CargoResult)>>> { + if let Some(mut val) = self.get_list_or_split_string(key)? { + if !val.val.is_empty() { + return Ok(Some(Value { + val: (self.string_to_path(val.val.remove(0), &val.definition), val.val), + definition: val.definition + })); + } + } + Ok(None) + } + pub fn get_list(&self, key: &str) -> CargoResult>>> { match self.get(key)? { diff --git a/tests/tool-paths.rs b/tests/tool-paths.rs index 641ccba9a..ef1a183d9 100644 --- a/tests/tool-paths.rs +++ b/tests/tool-paths.rs @@ -140,7 +140,7 @@ fn custom_runner() { .file("benches/bench.rs", "") .file(".cargo/config", &format!(r#" [target.{}] - runner = "nonexistent-runner" + runner = "nonexistent-runner -r" "#, target)); foo.build(); @@ -149,7 +149,7 @@ fn custom_runner() { execs().with_stderr_contains(&format!("\ [COMPILING] foo v0.0.1 ({url}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `nonexistent-runner target[/]debug[/]foo[EXE] --param` +[RUNNING] `nonexistent-runner -r target[/]debug[/]foo[EXE] --param` ", url = foo.url()))); assert_that(foo.cargo("test").args(&["--test", "test", "--verbose", "--", "--param"]), @@ -157,7 +157,7 @@ fn custom_runner() { [COMPILING] foo v0.0.1 ({url}) [RUNNING] `rustc [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `nonexistent-runner [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param` +[RUNNING] `nonexistent-runner -r [..][/]target[/]debug[/]deps[/]test-[..][EXE] --param` ", url = foo.url()))); assert_that(foo.cargo("bench").args(&["--bench", "bench", "--verbose", "--", "--param"]), @@ -166,6 +166,6 @@ fn custom_runner() { [RUNNING] `rustc [..]` [RUNNING] `rustc [..]` [FINISHED] release [optimized] target(s) in [..] -[RUNNING] `nonexistent-runner [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench` +[RUNNING] `nonexistent-runner -r [..][/]target[/]release[/]deps[/]bench-[..][EXE] --param --bench` ", url = foo.url()))); } -- 2.30.2